const action_ping = async () => {
  const response = await mainapp.ping()
  console.log(response) // 打印 'pong'
  return response
}


const information = document.getElementById('info')
information.innerText = `This app is using Chrome (v${mainapp.chrome()}), Node.js (v${mainapp.node()}), and Electron (v${mainapp.electron()})`

const pingButton = document.getElementById('pingButton')
pingButton.addEventListener('click', () => {
  action_ping()
    .then(response => {
      console.log(response) // 打印 'pong'
      information.innerText = `Ping response: ${response}`
    })
    .catch(error => {
      console.error('Error:', error)
      information.innerText = `Error: ${error.message}`
    })
})

const counter = document.getElementById('counter')

window.versions.onUpdateCounter((value) => {
  const oldValue = Number(counter.innerText)
  const newValue = oldValue + value
  counter.innerText = newValue.toString()
  window.mainapp.counterValue(newValue)
})